package com.chance.cc.crawler.development.bootstrap.weibo.weiboapi;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;
import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerRequestType.*;

/**
 * @ClassName weibo
 * @Description TODO
 * @Author songding
 * @Date 2021/9/23 17:19
 * @Version 1.0
 * 微博接口 新脚本
 **/
public class WeiApiNewStart {
    public static final String domain = "weibo";
    public static final String site = "newWeibo";

    private static final String limitRegulars = "https://c.api.weibo.com/2/search/statuses/limited.json";//微博根据关键字搜集微博
    private static final String countBizRegulars = "https://c.api.weibo.com/2/statuses/count/biz.json";//微博根据mid采集互动量
    private static final String otherRegulars = "https://c.api.weibo.com/2/users/show_batch/other.json"; //微博根据uid采集用户信息
    private static final String otherTagRegulars = "https://c.api.weibo.com/2/tags/tags_batch/other.json"; //微博根据uid获取用户标签
    private static final String otherAgeRegulars = "https://c.api.weibo.com/2/users/birthday/other.json";//微博根据uid获取用户年龄

    public static void main(String[] args) {

    }
    public static void article(){
        CrawlerRequestRecord requestRecord = null;
        requestRecord = limit();
        //requestRecord = all();

        String keyword = requestRecord.tagsCreator().bizTags().getCategoryTag().getKVTagStrVal("keyword");
        CrawlerRequestRecord keywordRecord = CrawlerRequestRecord.builder()
                .startPageRequest("keyword",turnPageItem)
                .httpUrl(keyword)
                .requestLabelTag(supportSource)
                .requestLabelTag(internalDownload)
                .build();

        DevCrawlerController.builder()
                .triggerInfo(domain,domain,System.currentTimeMillis(),domain)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline()
                .fileResultPipeline("kafka","F:\\chance_log\\weibo\\data.log",true)
                .fileResultPipeline("redis","F:\\chance_log\\weibo\\data.log",true)
                .requestRecord(requestRecord)
                //.supportRecord(keywordRecord)
                .build("com.chance.cc.crawler.development.scripts.weibo")
                .start();
    }
    public static CrawlerRequestRecord limit(){
        String url = limitRegulars;
        String keyword = "";
        CrawlerRequestRecord requestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain,CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpUrl(url)
                .httpConfig(HttpConfig.me(domain))
                .releaseTime(System.currentTimeMillis())
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*7,null))
                .build();
        requestRecord.setSkipPipeline(true);
        requestRecord.setDownload(false);
        requestRecord.tagsCreator().bizTags().addDomain(domain);
        requestRecord.tagsCreator().bizTags().addSite(site);
        //关键词
        requestRecord.tagsCreator().bizTags().addCustomKV("keyword",keyword);

        requestRecord.tagsCreator().bizTags().addCustomKV("midInteraction",true);//是否需要互动量
        requestRecord.tagsCreator().bizTags().addCustomKV("userMessage",true);//是否需要用户信息
        requestRecord.tagsCreator().bizTags().addCustomKV("userTag",true);//是否需要用户标签
        requestRecord.tagsCreator().bizTags().addCustomKV("userAge",true);//是否需要用户年龄

        return requestRecord;
    }

    public static CrawlerRequestRecord all(){
        String url = countBizRegulars;//根据mid采集互动量
        //String url = otherRegulars;//根据uid采集用户信息
        //String url = otherTagRegulars;//根据uid获取用户标签
        //String url = otherAgeRegulars;根据uid获取用户年龄
        String keyword = "";
        CrawlerRequestRecord requestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain,CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpUrl(url)
                .httpConfig(HttpConfig.me(domain))
                .releaseTime(System.currentTimeMillis())
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*7,null))
                .build();
        requestRecord.setSkipPipeline(true);
        requestRecord.setDownload(false);
        requestRecord.tagsCreator().bizTags().addDomain(domain);
        requestRecord.tagsCreator().bizTags().addSite(site);
        //关键词
        requestRecord.tagsCreator().bizTags().addCustomKV("keyword",keyword);

        return requestRecord;
    }




    @Test
    public void test(){
        String TimeNow = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
        System.out.println(TimeNow);
       /* String path ="F:\\chance_log";
        String task_id = "142611694";
        String secret_key = "0473e6f00ddd97b56d61";
        try {
            ZipFile zip = new ZipFile("F:\\chance_log\\task_142611694.zip");
            zip.setFileNameCharset("GBK");
            zip.setPassword(task_id+secret_key);
            zip.extractAll(path);

        } catch (ZipException e) {
            e.printStackTrace();
        }*/
    }


}
